package com.itheima.service;
import com.itheima.dao.DeptDao;
import com.itheima.dao.DeptDaoImpl;
import com.itheima.entity.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.util.List;
//@Component
public class DeptServiceImpl implements DeptService{
//    private DeptDao deptDao = new DeptDaoImpl();
//    @Autowired
    private DeptDao deptDao;
    public List<Dept> list(){
        List<String> stringList = deptDao.list();
        List<Dept> depts = stringList.stream().map((str)->{
            String[] parts = str.split(",");
            Integer id =  Integer.valueOf(parts[0]);
            String name = parts[1];
            LocalDateTime updateTime = LocalDateTime.parse(parts[2], DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
            return new Dept(id,name,updateTime);
        }).toList();
        return depts;
    }
}
